package com.naiterui.ehp.bs.agent.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.naiterui.common.repository.core.BaseJpaRepository;
import com.naiterui.ehp.bs.agent.entity.AsAgentInviteCount;

/**
 * 经纪人统计-邀请医生
 *
 * @author yangfuya
 * @since 2022/2/16
 */
@Repository
public interface IAsAgentInviteCountRepository extends BaseJpaRepository<AsAgentInviteCount, Long> {
	@Query(value = "select * from as_agent_invite_count where agent_id = :agentId and generate_date =:generateDate limit 1",
			nativeQuery = true)
	AsAgentInviteCount findByAgentIdAndGenerateDate(@Param("agentId")Long agentId, @Param("generateDate") String generateDate);

    @Query(value = "select *  from as_agent_invite_count where generate_date =:generateDate  limit 1",
        nativeQuery = true)
    AsAgentInviteCount getTotalByGenerateDate(@Param("generateDate") String generateDate);

	/**
	 * 根据经纪人查询客户数
	 * @param agentIds
	 * @return
	 */
	@Query(nativeQuery = true,
			value = "select agent_id, sum(new_number) new_number from as_agent_invite_count where agent_id in (:agentIds) group by agent_id")
	List<Object[]> findSummaryByAgentId(@Param("agentIds") List<Long> agentIds);
}
